{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}
{% import "user/partial/search_user_form.html" as search_user_form_macro %}
{% import "user/partial/user_table.html" as user_table_macro %}

{% block title %}万屏时代OPC--客服拉新统计{% endblock %}

{% block panel_heading %}
    万屏时代OPC--客服拉新统计
{% endblock %}

{% block panel_body %}
    <form id="search-user-form" action="{{ url_for('op_bp.invite_stat') }}"
          method="post" class="form" role="form">
        {{ my_wtf_macros.form_field(form.demand_id, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.admin_id, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.mastery, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>

        {{ my_wtf_macros.form_field(form.call_time_begin, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.call_time_end, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        {{ my_wtf_macros.form_field(form.aspiration, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.is_invite_success, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.mobile, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="pull-right btn-group">
            <button type="submit" class="btn btn-info"
                    id="query-demand-btn">
                查询
            </button>
            {% if not current_user.is_agent %}
                <a
                        href="javascript:void(0);"
                        name="user-info"
                        target="_blank"
                        class="btn-group btn btn-primary"
                        id="export-user-info"
                >
                    导出
                </a>
            {% endif %}
        </div>
    </form>

    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, 'op_bp.invite_stat', **url_kwargs) }}
        </div>
    {% endif %}
    <div>
        <span>总外呼量：</span>
        <span>{{ invite_count.total_call or 0 }}&nbsp&nbsp&nbsp</span>
        <span>工程商数量：</span>
        <span>{{ invite_count.engineer_count or 0 }}&nbsp&nbsp&nbsp</span>
        <span>绑定数量：</span>
        <span>{{ invite_count.invite_count or 0 }}&nbsp&nbsp&nbsp</span>
    </div>
    <table id="cancel-attention-user-info-table"
           class="table table-bordered table-hover table-condensed table-striped">
        <thead>
        <tr>
            <th>用户ID</th>
            <th>工程商</th>
            <th>外呼客服</th>
            <th>通话状态</th>
            <th>绑定意愿</th>
            <th>专业度</th>
            <th>是否加微信</th>
            <th>关注状态</th>
            <th>绑定状况</th>
            <th>400客服</th>
        </tr>
        </thead>
        <tbody>
        {% for i in records %}
            <tr>
                <td>{{ i.user_id }}</td>
                <td>
                    {% if i.user_id %}
                        <a
                                href="{{ url_for('op_bp.user_info', user_id=i.user_id) }}"
                                name="user-info"
                                target="_blank">
                            {{ i.mobile | encrypt }}
                            <br>
                            {{ i.nickname }}
                        </a>
                    {% else %}
                        {{ i.mobile | encrypt }}
                        <br>
                        {{ i.nickname }}
                    {% endif %}
                </td>
                <td>{{ i.admin_nickname }} <br> {{ i.call_time }}</td>
                <td>{{ call_result.get(i.call_result, '未知') }}</td>
                <td>{{ aspiration.get(i.aspiration, '未知') }}</td>
                <td>{{ mastery.get(i.mastery, '未知') }}</td>
                <td>{{ i.bind_user_name or '' }} <br> {{ i.bind_date or '' }}</td>
                <td>{{ follow_state.get(i.follow_state, '未知') }}</td>
                <td>{% if i.is_invite_success %}是{% else %}否{% endif %}</td>
                <td>{{ i.guide_name or '' }} <br> {{ i.guide_call_date or '' }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>

    {% if pagination %}
        <div class="pagination">
            {{ macros.pagination_widget(pagination, 'op_bp.invite_stat', **url_kwargs) }}
        </div>
    {% endif %}

{% endblock %}

{% block scripts %}
    {{ super() }}
    <script>
        $(document).ready(function () {
            $("#export-user-info").click(function () {
                var url = '{{ url_for('op_bp.export_invite_users') }}';
                url = url + '?' + 'call_time_begin=' + $('#call_time_begin').val() +
                    '&call_time_end=' + $('#call_time_end').val() +
                    '&admin_id=' + $('#admin_id').val() +
                    '&aspiration=' + $('#aspiration').val();
                if ($('#is_invite_success').is(':checked')) {
                    url = url + '&is_invite_success=1'
                }
                window.location.href = url;
            });
        })
    </script>
{% endblock %}
